package com.wnxy.sddfp.system.config;

import org.hibernate.validator.HibernateValidator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;

@Configuration
public class ValidatorConfiguration {

    @Bean
    @ConditionalOnMissingBean(Validator.class)
    public Validator validator() {
        Validator validator = Validation
                .byProvider(HibernateValidator.class)
                .configure()
                .failFast(true)  // 校验的快速失败
                .buildValidatorFactory()
                .getValidator();
        return validator;
    }

}